﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PocketDOHS
{
    public partial class CondDent3 : Form
    {
        private TextBox txtFocus; 
                
        public CondDent3()
        {
            InitializeComponent();
        }

        private void btnAvanc_Click(object sender, EventArgs e)
        {
            FormsMethods.nextForm();
        }

        private void btnVoltar_Click(object sender, EventArgs e)
        {
            FormsMethods.prevForm();
        }

        private void btnLimp_Click(object sender, EventArgs e)
        {
            Limpar_txt_Form();
            txtCoroa38.Focus();
        }

        private void txtCoroaFocus(object sender, EventArgs e)
        {
            btn0.Enabled = true;
            btn1.Enabled = true;
            btn2.Enabled = true;
            btn3.Enabled = true;
            btn4.Enabled = true;
            btn5.Enabled = true;
            btn6.Enabled = true;
            btn7.Enabled = true;
            btn8.Enabled = true;
            btnT.Enabled = true;
            btnA.Enabled = false;
            btnB.Enabled = false;
            btnC.Enabled = false;
            btnD.Enabled = false;
            btnE.Enabled = false;
            btnF.Enabled = false;
            btnG.Enabled = false;
            btnP.Enabled = false;
            txtFocus = (TextBox)sender;
        }

        private void BotoesFalso()
        {
            btn0.Enabled = false;
            btn1.Enabled = false;
            btn2.Enabled = false;
            btn3.Enabled = false;
            btn4.Enabled = false;
            btn5.Enabled = false;
            btn6.Enabled = false;
            btn7.Enabled = false;
            btn8.Enabled = false;
            btn9.Enabled = false;
            btnA.Enabled = false;
            btnB.Enabled = false;
            btnC.Enabled = false;
            btnD.Enabled = false;
            btnE.Enabled = false;
            btnF.Enabled = false;
            btnG.Enabled = false;
            btnP.Enabled = false;
            btnT.Enabled = false;
        }

        private void txtRaizFocus(object sender, EventArgs e)
        {
            BotoesFalso();
            txtFocus = (TextBox)sender;
            ValidacaoCodRaiz((TextBox)sender);
        }

        public void txtTratamentoFocus(object sender, EventArgs e)
        {
            BotoesFalso();
            txtFocus = (TextBox)sender;
            ValidacaoCodTratamento((TextBox)sender);
        }

        private void WriteTextBox(object sender, EventArgs e)
        {
            FormsMethods.WriteTextBox((Button)sender, txtFocus, this);
        }

        private void ValidacaoCodRaiz(TextBox sender)
        {
            string codCoroa = "";

            switch (sender.Name)
            {
                case "txtRaiz38":
                    codCoroa = txtCoroa38.Text;
                    break;
                case "txtRaiz37":
                    codCoroa = txtCoroa37.Text;
                    break;
                case "txtRaiz36":
                    codCoroa = txtCoroa36.Text;
                    break;
                case "txtRaiz35":
                    codCoroa = txtCoroa35.Text;
                    break;
                case "txtRaiz34":
                    codCoroa = txtCoroa34.Text;
                    break;
                case "txtRaiz33":
                    codCoroa = txtCoroa33.Text;
                    break;
                case "txtRaiz32":
                    codCoroa = txtCoroa32.Text;
                    break;
                case "txtRaiz31":
                    codCoroa = txtCoroa31.Text;
                    break;
            }
            if (codCoroa == "4" || codCoroa == "5" || codCoroa == "8" || codCoroa == "E")
            {
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn3.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
        }

        private void ValidacaoCodTratamento(TextBox sender)
        {
            string codCoroa = "";
            string codRaiz = "";

            switch (sender.Name)
            {
                case "txtTrat38":
                    codCoroa = txtCoroa38.Text;
                    codRaiz = txtRaiz38.Text;
                    break;
                case "txtTrat37":
                    codCoroa = txtCoroa37.Text;
                    codRaiz = txtRaiz37.Text;
                    break;
                case "txtTrat36":
                    codCoroa = txtCoroa36.Text;
                    codRaiz = txtRaiz36.Text;
                    break;
                case "txtTrat35":
                    codCoroa = txtCoroa35.Text;
                    codRaiz = txtRaiz35.Text;
                    break;
                case "txtTrat34":
                    codCoroa = txtCoroa34.Text;
                    codRaiz = txtRaiz34.Text;
                    break;
                case "txtTrat33":
                    codCoroa = txtCoroa33.Text;
                    codRaiz = txtRaiz33.Text;
                    break;
                case "txtTrat32":
                    codCoroa = txtCoroa32.Text;
                    codRaiz = txtRaiz32.Text;
                    break;
                case "txtTrat31":
                    codCoroa = txtCoroa31.Text;
                    codRaiz = txtRaiz31.Text;
                    break;
            }

            if (codCoroa == "1" || codCoroa == "2" || codCoroa == "B" || codCoroa == "C")
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn5.Enabled = true;
                btn6.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else if (codCoroa == "3" || codCoroa == "D")
            {
                btn0.Enabled = true;
                btn9.Enabled = true;
                if (codRaiz == "0" || codRaiz == "8")
                {
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "1" || codRaiz == "2")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                }
                else if (codRaiz == "3")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "7")
                {
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else
                    btnP.Enabled = true;
            }
            else if (codCoroa == "4" || codCoroa == "5" || codCoroa == "8" || codCoroa == "E")
            {
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
            }
            else if (codCoroa == "6" || codCoroa == "F")
            {
                btn0.Enabled = true;
                btn9.Enabled = true;
                if (codRaiz == "0")
                {
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "1" || codRaiz == "2")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                }
                else if (codRaiz == "3")
                {
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btnP.Enabled = true;
                }
                else if (codRaiz == "7")
                {
                    btn0.Enabled = true;
                    btn1.Enabled = true;
                    btn2.Enabled = true;
                    btn3.Enabled = true;
                    btn4.Enabled = true;
                    btn5.Enabled = true;
                    btn6.Enabled = true;
                    btn7.Enabled = true;
                    btn8.Enabled = true;
                    btn9.Enabled = true;
                    btnA.Enabled = true;
                    btnB.Enabled = true;
                    btnC.Enabled = true;
                    btnD.Enabled = true;
                    btnE.Enabled = true;
                    btnF.Enabled = true;
                    btnP.Enabled = true;
                }
            }
            else if (codCoroa == "7" || codCoroa == "G")
            {
                btn0.Enabled = true;
                btn1.Enabled = true;
                btn2.Enabled = true;
                btn3.Enabled = true;
                btn4.Enabled = true;
                btn5.Enabled = true;
                btn6.Enabled = true;
                btn7.Enabled = true;
                btn8.Enabled = true;
                btn9.Enabled = true;
                btnA.Enabled = true;
                btnB.Enabled = true;
                btnC.Enabled = true;
                btnD.Enabled = true;
                btnE.Enabled = true;
                btnF.Enabled = true;
                btnP.Enabled = true;
            }
        }

        #region CoroaChaged

        private void txtCoroa31_TextChanged(object sender, EventArgs e)
        {
            txtRaiz31.Text = "0";
            txtTrat31.Text = "0";
            txtRaiz31.Focus();
        }

        private void txtCoroa32_TextChanged(object sender, EventArgs e)
        {
            txtRaiz32.Text = "0";
            txtTrat32.Text = "0";
            txtRaiz32.Focus();
        }

        private void txtCoroa33_TextChanged(object sender, EventArgs e)
        {
            txtRaiz33.Text = "0";
            txtTrat33.Text = "0";
            txtRaiz33.Focus();
        }

        private void txtCoroa34_TextChanged(object sender, EventArgs e)
        {
            txtRaiz34.Text = "0";
            txtTrat34.Text = "0";
            txtRaiz34.Focus();
        }

        private void txtCoroa35_TextChanged(object sender, EventArgs e)
        {
            txtRaiz35.Text = "0";
            txtTrat35.Text = "0";
            txtRaiz35.Focus();
        }

        private void txtCoroa36_TextChanged(object sender, EventArgs e)
        {
            txtRaiz36.Text = "0";
            txtTrat36.Text = "0";
            txtRaiz36.Focus();
        }

        private void txtCoroa37_TextChanged(object sender, EventArgs e)
        {
            txtRaiz37.Text = "0";
            txtTrat37.Text = "0";
            txtRaiz37.Focus();
        }
  
        private void txtCoroa38_TextChanged(object sender, EventArgs e)
        {
            txtRaiz38.Text = "0";
            txtTrat38.Text = "0";
            txtRaiz38.Focus();
        }

        #endregion

        #region RaizChanged

        private void txtRaiz38_TextChanged(object sender, EventArgs e)
        {
            txtTrat38.Text = "0";
            txtTrat38.Focus();
        }

        private void txtRaiz37_TextChanged(object sender, EventArgs e)
        {
            txtTrat37.Text = "0";
            txtTrat37.Focus();
        }

        private void txtRaiz36_TextChanged(object sender, EventArgs e)
        {
            txtTrat36.Text = "0";
            txtTrat36.Focus();
        }

        private void txtRaiz35_TextChanged(object sender, EventArgs e)
        {
            txtTrat35.Text = "0";
            txtTrat35.Focus();
        }

        private void txtRaiz34_TextChanged(object sender, EventArgs e)
        {
            txtTrat34.Text = "0";
            txtTrat34.Focus();
        }

        private void txtRaiz33_TextChanged(object sender, EventArgs e)
        {
            txtTrat33.Text = "0";
            txtTrat33.Focus();
        }

        private void txtRaiz32_TextChanged(object sender, EventArgs e)
        {
            txtTrat32.Text = "0";
            txtTrat32.Focus();
        }

        private void txtRaiz31_TextChanged(object sender, EventArgs e)
        {
            txtTrat31.Text = "0";
            txtTrat31.Focus();
        }

        #endregion

        #region TratamentoChanged

            private void txtTrat31_TextChanged(object sender, EventArgs e)
            {
                btnAvanc.Focus();
            }

            private void txtTrat32_TextChanged(object sender, EventArgs e)
            {
                txtCoroa31.Focus();
            }

            private void txtTrat33_TextChanged(object sender, EventArgs e)
            {
                txtCoroa32.Focus();
            }

            private void txtTrat34_TextChanged(object sender, EventArgs e)
            {
                txtCoroa33.Focus();
            }

            private void txtTrat35_TextChanged(object sender, EventArgs e)
            {
                txtCoroa34.Focus();
            }

            private void txtTrat36_TextChanged(object sender, EventArgs e)
            {
                txtCoroa35.Focus();
            }

            private void txtTrat37_TextChanged(object sender, EventArgs e)
            {
                txtCoroa36.Focus();
            }

            private void txtTrat38_TextChanged(object sender, EventArgs e)
            {
                txtCoroa37.Focus();
            }

        #endregion

            private void CondDent3_Activated(object sender, EventArgs e)
            {
                if (FormsMethods.Inicializa[FormsMethods.VetIndex])
                {
                    Limpar_txt_Form();
                    FormsMethods.Inicializa[FormsMethods.VetIndex] = false;
                    txtCoroa38.Focus();
                }
                if (FormsMethods.Altera.ToArray()[FormsMethods.VetIndex])
                {
                    FormsMethods.preencheForms();
                    FormsMethods.Altera[FormsMethods.VetIndex] = false;
                }
            }

            private void Limpar_txt_Form() 
            {
                txtCoroa38.Text = "0";
                txtCoroa37.Text = "0";
                txtCoroa36.Text = "0";
                txtCoroa35.Text = "0";
                txtCoroa34.Text = "0";
                txtCoroa33.Text = "0";
                txtCoroa32.Text = "0";
                txtCoroa31.Text = "0";
                txtRaiz38.Text = "0";
                txtRaiz37.Text = "0";
                txtRaiz36.Text = "0";
                txtRaiz35.Text = "0";
                txtRaiz34.Text = "0";
                txtRaiz33.Text = "0";
                txtRaiz32.Text = "0";
                txtRaiz31.Text = "0";
                txtTrat38.Text = "0";
                txtTrat37.Text = "0";
                txtTrat36.Text = "0";
                txtTrat35.Text = "0";
                txtTrat34.Text = "0";
                txtTrat33.Text = "0";
                txtTrat32.Text = "0";
                txtTrat31.Text = "0";
            }

    }
}